package com.wtwd.wtwddevice.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.wtwd.wtwddevice.mapper.DeviceBloodPressureTotalMapper;
import com.wtwd.wtwddevice.model.entity.DeviceBloodPressureTotal;
import com.wtwd.wtwddevice.service.IDeviceBloodPressureTotalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2024-05-29
 */
@Service
public class DeviceBloodPressureTotalServiceImpl extends ServiceImpl<DeviceBloodPressureTotalMapper, DeviceBloodPressureTotal> implements IDeviceBloodPressureTotalService {

    @Resource
    private DeviceBloodPressureTotalMapper deviceBloodPressureTotalMapper;

    @Override
    public DeviceBloodPressureTotal getDeviceBloodPressureTotal(Long deviceId, String time) {
        return new LambdaQueryChainWrapper<>(deviceBloodPressureTotalMapper)
                .eq(DeviceBloodPressureTotal::getDeviceId, deviceId)
                .eq(DeviceBloodPressureTotal::getTime, time)
                .one();
    }

    @Override
    public boolean insertOrUpdate(DeviceBloodPressureTotal deviceBloodPressureTotal) {
        if (deviceBloodPressureTotal==null){
            return false;
        }
        deviceBloodPressureTotal.setUpdateTime(new Date().getTime());
        return deviceBloodPressureTotalMapper.insertOrUpdate(deviceBloodPressureTotal)>0?true:false;
    }


}
